Skip to content

initial mosaics cli + async client #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

initial mosaics cli + async client #1131

wants to merge 3 commits into from

Conversation

ischneider
Copy link
Member

WIP - mosaics API support

I based this on the V1 CLI/SDK but added some additional functionality, mostly in filters that have been added since the original client was created.

Rather than implement the sync SDK and fully document every parameter and write every test, I decided to get this out for some tire kicking first... so there might be a broken thing or two but pretty sure everything is working

The examples/mosaics-cli.sh script demonstrates some basic functionality and will download 2 quads to the directory it's run from.

General questions that popped up while developing:

  1. Some operations do too much (without filters), e.g. list mosaics (for Planet users is 1000s of results), list/download quads for large (or default) extents

  2. Download operations have an overwrite flag but this requires checking the content-disposition header to get the destination file name (at least with the current core implementation) though this will result in the request counting as a "download" (for quota) even if the stream is never read...

  3. Some operations accept a name or ID (as a convenience, since ID is opaque) and others require a dict of the the resource representation - it would be nice to allow any of the above, i.e. NameIDObject = Union[dict, str] (this name is terrible but what should it be?)

Proposals (where I have an idea):

  1. For requests that do too much: limit can be confusing when there's a default and users may not be aware of it. Instead, the CLI command can fail once too many results are processed. For quads, could use a heuristic based on quads/square-degree (e.g. the 10 degree bounding box you are supplying will download approximately 4733 quads) and prompt the user?

  2. The v0 basemaps API used a primary quad identifier that contained the zoom and tile coordinates in northing and easting, left padded with zeros, e.g. L15-0450E-1275N.tif. Since the v1 API only allows access to native resolution (you cannot get L14), and the padding is terribly useful, propose changing the default name to simply the quad-id (450-1275 in this case) with the option of auto-creating a directory with the name of the mosaic. Or, more forward thinking, allow choosing one of several built-in output formats. This would require modification of planet.models.StreamingBody (https://github.com/planetlabs/planet-client-python/blob/main/planet/models.py#L82) to allow specifying the output name.

Related Issue(s):

Closes #446

Proposed Changes:

For inclusion in changelog (if applicable):

  1. Initial support for mosaics API

PR Checklist:

  • [] This PR is as small and focused as possible
  • [] If this PR includes proposed changes for inclusion in the changelog, the title of this PR summarizes those changes and is ready for inclusion in the Changelog.
  • [] I have updated docstrings for function changes and docs in the 'docs' folder for user interface / behavior changes
  • [] This PR does not break any examples or I have updated them

(Optional) @mentions for Notifications:

@ischneider ischneider marked this pull request as draft May 12, 2025 20:26
@ischneider ischneider force-pushed the mosaics-api branch 2 times, most recently from fbd75a4 to 8b4530a Compare May 12, 2025 21:48
@joferkington
Copy link
Contributor

joferkington commented May 13, 2025

Thanks a ton for this!!

Minor doc comment that could be addressed later: It's a bit unclear from the CLI --help docs that name can be either an ID or a name. I think allowing either ID or name in the CLI as the same argument is a great idea! It's just not immediately clear to someone who isn't reading the code that that's an option. The examples also could be interpreted to show that series operations use name and mosaic operations use ID.

With that said, that's a very minor nitpick that could be handled via more examples or other documentation. I know you separately mentioned it for the python client side, but honestly it's the CLI docs that I think it's the least clear in currently.


async def download_quad(self,
quad: dict,
directory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Data API client, the directory arg defaults to current dir. Is it worth making that consistent? I also think your idea of defaulting to the mosaic name would work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed the default for directory to current for the client - the quad object doesn't have any direct reference to the mosaic name but I did make this the behavior from the CLI

planet mosaics contributions 09462e5a-2af0-4de3-a710-e9010d8d4e58 455-1273

echo -e "\nDownload Them!"
planet mosaics download 09462e5a-2af0-4de3-a710-e9010d8d4e58 --bbox=-100,40,-100,40.1 --output-dir=quads
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious if we think users might need guard rails for this. Could this be a significant enough amount of data to warrant a confirmation step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was one of the issues (1) I raised in the MR description.

@ischneider
Copy link
Member Author

Thanks @joferkington

Minor doc comment that could be addressed later: It's a bit unclear from the CLI --help docs that name can be either an ID or a name. I think allowing either ID or name in the CLI as the same argument is a great idea! It's just not immediately clear to someone who isn't reading the code that that's an option. The examples also could be interpreted to show that series operations use name and mosaic operations use ID.

Yes, good call to make this clearer. Initially I tried to add help to the click argument but it doesn't allow that - seems the appropriate way is to add details to the doc string for the command, so I'll do that.

As for the examples, I did not consider that interpretation - will make that clearer!

@ischneider ischneider force-pushed the mosaics-api branch 2 times, most recently from 45bedc9 to d3b88b7 Compare May 28, 2025 16:51
- make it clearer that name or ID can be used to lookup items
- add typed dicts to represent API responses/resources
- accept typed dict or name/ID when possible
- raise MissingResource when attempting a get by name with no match
- use positional/keyword-only parameters in client methods
@ischneider ischneider force-pushed the mosaics-api branch 2 times, most recently from 4807f06 to e496b48 Compare May 29, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement support for Basemaps API
3 participants